package cn.tank.controller;

import cn.tank.pojo.Resume;
import cn.tank.service.impl.ResumeServiceImpl;
import net.bytebuddy.implementation.bind.annotation.Default;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: ZLY
 * @Date: 2020/10/31 14:58
 * @Description:
 */
@Controller
@RequestMapping("/resume")
public class ResumeController {
    @Autowired
    private ResumeServiceImpl resumeService;

    @RequestMapping("/list")
    public String list(Model model){
        List<Resume> resumes = resumeService.queryAll();
        model.addAttribute("resumes",resumes);
        return "list";
    }

    @RequestMapping("/update")
    public String update(Model model,Long id){
        if(id!=null){
            Resume resume = resumeService.queryById(id);
            model.addAttribute("resume",resume);
            model.addAttribute("isAdd",false);
        }else {
            model.addAttribute("isAdd",true);
        }
        return "update";
    }

    @RequestMapping("/save")
    public String save(Resume resume){
        resumeService.save(resume);
        return "redirect:list";
    }

    @RequestMapping("/del")
    public String del(Long id){
        resumeService.del(id);
        return "redirect:list";
    }


}
